package com.gientech.drools_service.controller;

import com.gientech.drools_service.entity.City;
import com.gientech.drools_service.entity.Custom;
import com.gientech.drools_service.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/provider")
public class CustomController {
    @Autowired
    private RuleService ruleService;

  //  @GetMapping("/matchCustom")
    @PostMapping("/matchCustom")
    public Custom queryCustom(@RequestBody Custom custom){
        City city = new City();
        List<String> list1= new ArrayList<>();
        List<String> list2= new ArrayList<>();

        list1.add("贵阳");
        list1.add("银川");
        list1.add("拉萨");
        list1.add("西宁");
        city.setPoorCities(list1);

        list2.clear();
        list2.add("北京");
        list2.add("上海");
        list2.add("广州");
        list2.add("深圳");
        city.setDevelopedCities(list2);

        Custom result = ruleService.executeRule(custom, city);

        // 计算最终的执行利率
        result.setIntRate(result.getBaseIntRate()+result.getFloatPoint());

        return result;
    }
}
